package java19_4_27.com.huweilong.timer;

import java.util.concurrent.TimeUnit;

public class ImplTimer1 {
    static class MyThread extends Thread {
        Runnable task;
        long delay;

        MyThread(Runnable task, long delay) {
            this.task = task;
            this.delay = delay;
        }

        @Override
        public void run() {
            try {
                Thread.sleep(delay);
                task.run();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Runnable task = new Runnable() {
            @Override
            public void run() {
                System.out.println("时间到了");
            }
        };

        MyThread t = new MyThread(task, 5000);
        t.start();

        while (true) {}
    }
}
